package com.polaris.live.im.db.dao

import androidx.room.*
import com.polaris.live.im.db.entity.PurchaseOrderEntity

/**
 * PurchaseOrderEntityDao
 *
 * @author Created by lucas on 2023/11/23 10:47
 * @since 1.0.0
 */
@Dao
interface PurchaseOrderEntityDao {

    /**
     * 保存
     */
    @Insert
    suspend fun save(entity: PurchaseOrderEntity): Long

    /**
     * 查询用户的所有未成功消费的订单
     */
    @Query("select * from purchase_order where user_id = :userId")
    suspend fun findByUserId(userId: Long): List<PurchaseOrderEntity>

    /**
     * 删除订单
     */
    @Query("delete from purchase_order where purchase_token = :purchaseToken")
    suspend fun delete(purchaseToken: String)

    /**
     * 清理冗余数据
     */
    @Query("delete from purchase_order where timestamp < :timestamp")
    suspend fun clearRedundancy(timestamp: Long)

}